package com.moyq5.mvc.maker.test.bean.entity;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import com.moyq5.mvc.maker.test.bean.custom.NotifyEntity;
import com.moyq5.mvc.maker.test.bean.enums.RemitCheckStatus;
import com.moyq5.mvc.maker.test.bean.enums.RemitPayStatus;
import com.moyq5.mvc.maker.test.bean.enums.RemitPayType;
import com.moyq5.mvc.maker.test.bean.enums.RemitType;
import com.moyq5.mvc.maker.test.bean.enums.SysOperatorType;
import com.moyq5.mvc.maker.test.bean.enums.SysOwnerType;

/**
 * 出款订单
 * @author Moyq5
 * @date 2017年12月12日
 */
@Entity
@Table(name = "tra_remit",indexes={@Index(columnList="add_time")})
@DynamicUpdate
public class TraRemit extends NotifyEntity implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	/**
	 * 出款单ID
	 */
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "native")@GenericGenerator(name = "native", strategy = "native")
    @Column(name = "remit_id")
	private Long remitId;
	/**
	 * 出款流水号（平台单号）
	 */
	@Column(name = "remit_no", length = 30, nullable = false, unique = true)
	private String remitNo;
	/**
	 * 商家
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "merch_id")
	private Merch merch;
	/**
	 * 代理商
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "agent_id", nullable = false)
	private Agent agent;
	/**
	 * 归属类型
	 */
	@Enumerated(EnumType.ORDINAL)
	@Column(name = "owner_type", precision = 2, nullable = false)
	private SysOwnerType ownerType;
	/**
	 * 出款渠道
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "channel_order_id")
	private TraChannelOrder channelOrder;
	/**
	 * 商品名称
	 */
	@Column(name = "name", length = 200, nullable = false)
	private String name;
	/**
	 * 出款类型
	 */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "type", precision = 2, nullable = false, columnDefinition = "int(2) default '0'")
	private RemitType type;
	/**
	 * 交易金额（元），申请金额
	 */
	@Column(name = "amount", precision = 10, scale = 2, nullable = false)
	private BigDecimal amount;
	/**
	 * 出款金额
	 */
	@Column(name = "pay_amount", precision = 10, scale = 2, nullable = false)
	private BigDecimal payAmount;
	/**
	 * 单笔费率，如：0.0049
	 */
	@Column(name = "rate", precision = 5, scale = 4, nullable = false)
	private BigDecimal rate;
	/**
	 * 单笔手续费（元）
	 */
	@Column(name = "fee", precision = 10, scale = 2, nullable = false)	
	private BigDecimal fee;
	/**
	 * 总手续费（元）
	 */
	@Column(name = "total_fee", precision = 10, scale = 2, nullable = false)	
	private BigDecimal totalFee;
	/**
	 * 出款方式
	 */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "pay_type", precision = 2, nullable = false)
	private RemitPayType payType;
    /**
     * 复核状态，即商户对提现记录进行核实确认要出款后，系统才会对其执行出款操作
     */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "check_status", precision = 2, nullable = false)
	private RemitCheckStatus checkStatus;
	/**
	 * 出款状态
	 */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "pay_status", precision = 2, nullable = false)
	private RemitPayStatus payStatus;
	/**
	 * 出款状态描述
	 */
	@Column(name = "pay_descr", length = 300)
	private String payDescr;
	/**
	 * 出款时间
	 */
	@Column(name = "pay_time", columnDefinition="datetime")
	private Date payTime;
	/**
	 * 扣款账户
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "virtual_account_id", nullable = false)
	private VirtualAccount virtualAccount;
	/**
	 * 收款账户
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "account_id", nullable = false)
	private TraAccount account;
	/**
	 * 操作人类型
	 */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "operator_type", precision = 2, nullable = false)
	private SysOperatorType operatorType;
    /**
	 * 操作人（管理员）
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "admin_id")
	private SysAdmin operatorAdmin;
	/**
	 * 添加时间（交易时间）
	 */
	@Column(name = "add_time", nullable = false, columnDefinition="datetime")
	private Date addTime;
	
	@PrePersist
	public void prePersist() {
		super.prePersist();
		if (null == addTime) {
			addTime = new Date();
		}
		if (null == remitNo) {
			remitNo = (Long.MAX_VALUE|new Date().getTime()) + "" + Math.round(Math.random()*Integer.MAX_VALUE);
		}
		if (null == checkStatus) {
			checkStatus = RemitCheckStatus.UNCHECKED;
		}
	}
	public Long getRemitId() {
		return remitId;
	}
	public void setRemitId(Long remitId) {
		this.remitId = remitId;
	}
	public String getRemitNo() {
		return remitNo;
	}
	public void setRemitNo(String remitNo) {
		this.remitNo = remitNo;
	}
	public RemitType getType() {
		return type;
	}
	public void setType(RemitType type) {
		this.type = type;
	}
	public BigDecimal getAmount() {
		return amount;
	}
	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}
	public BigDecimal getFee() {
		return fee;
	}
	public void setFee(BigDecimal fee) {
		this.fee = fee;
	}
	public TraAccount getAccount() {
		return account;
	}
	public void setAccount(TraAccount account) {
		this.account = account;
	}
	public BigDecimal getPayAmount() {
		return payAmount;
	}
	public void setPayAmount(BigDecimal payAmount) {
		this.payAmount = payAmount;
	}
	public RemitPayType getPayType() {
		return payType;
	}
	public void setPayType(RemitPayType payType) {
		this.payType = payType;
	}
	public RemitPayStatus getPayStatus() {
		return payStatus;
	}
	public void setPayStatus(RemitPayStatus payStatus) {
		this.payStatus = payStatus;
	}
	public String getPayDescr() {
		return payDescr;
	}
	public void setPayDescr(String payDescr) {
		this.payDescr = payDescr;
	}
	public Date getPayTime() {
		return payTime;
	}
	public void setPayTime(Date payTime) {
		this.payTime = payTime;
	}
	public Date getAddTime() {
		return addTime;
	}
	public void setAddTime(Date addTime) {
		this.addTime = addTime;
	}
	public TraChannelOrder getChannelOrder() {
		return channelOrder;
	}
	public void setChannelOrder(TraChannelOrder channelOrder) {
		this.channelOrder = channelOrder;
	}
	public VirtualAccount getVirtualAccount() {
		return virtualAccount;
	}
	public void setVirtualAccount(VirtualAccount virtualAccount) {
		this.virtualAccount = virtualAccount;
	}
	public SysOperatorType getOperatorType() {
		return operatorType;
	}
	public void setOperatorType(SysOperatorType operatorType) {
		this.operatorType = operatorType;
	}
	public SysAdmin getOperatorAdmin() {
		return operatorAdmin;
	}
	public void setOperatorAdmin(SysAdmin operatorAdmin) {
		this.operatorAdmin = operatorAdmin;
	}
	public BigDecimal getRate() {
		return rate;
	}
	public void setRate(BigDecimal rate) {
		this.rate = rate;
	}
	public BigDecimal getTotalFee() {
		return totalFee;
	}
	public void setTotalFee(BigDecimal totalFee) {
		this.totalFee = totalFee;
	}
	public Merch getMerch() {
		return merch;
	}
	public void setMerch(Merch merch) {
		this.merch = merch;
	}
	public Agent getAgent() {
		return agent;
	}
	public void setAgent(Agent agent) {
		this.agent = agent;
	}
	public SysOwnerType getOwnerType() {
		return ownerType;
	}
	public void setOwnerType(SysOwnerType ownerType) {
		this.ownerType = ownerType;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public RemitCheckStatus getCheckStatus() {
		return checkStatus;
	}
	public void setCheckStatus(RemitCheckStatus checkStatus) {
		this.checkStatus = checkStatus;
	}
	
}
